//
//  IndexPage.m
//  SlimmingWar
//
//  Created by ZGS on 12-3-17.
//  Copyright 2012年 110. All rights reserved.
//

#import "IndexPage.h"


@implementation IndexPage
- (id) init
{
    self = [super init];
    if (self) {
        self.view.frame = CGRectMake(0, 0, 320, 480);
        self.title = @"";
        
    }
    return self;
}


-(void)viewDidLoad 
{
    self.navigationController.navigationBar.frame = CGRectMake(0, 20, 320, 30); 
    self.title = @"";
      
    //设置背景图片
    UIImageView *background = [[UIImageView alloc]initWithFrame:CGRectMake(0, -20, 320, 430)];
    [background setImage:[UIImage imageNamed:@"bg.png"]];
    [self.view addSubview:background];
    [background release];
    
    //人物背景图层
    UIImageView *homePageBoard = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 300, 180)];
    [homePageBoard setImage:[UIImage imageNamed:@"homePageBoard.png"]];
    [self.view addSubview:homePageBoard];
    [homePageBoard release];
    
    //人物图层
    UIImageView *homePageGirl = [[UIImageView alloc]initWithFrame:CGRectMake(40, -10, 100, 200)];
    [homePageGirl setImage:[UIImage imageNamed:@"homePageGirl.png"]];
    [self.view addSubview:homePageGirl];
    [homePageGirl release];
    
    //用户名
    UILabel *username = [[UILabel alloc]initWithFrame:CGRectMake(135, 20, 150, 30)];
    [username setBackgroundColor:[UIColor clearColor]];
    [username setText:@"Test"];
    [username setTextAlignment:UITextAlignmentCenter];
    [self.view addSubview:username];
    [username release];
    
    //华丽的分割线
    UIImageView *line = [[UIImageView alloc]initWithFrame:CGRectMake(135, 50, 150, 1)];
    [line setImage:[UIImage imageNamed:@"bmi_line_x.png"]];
    [self.view addSubview:line];
    [line release];
    
    //任务完成度提示文本
    UILabel *task = [[UILabel alloc]initWithFrame:CGRectMake(135, 51, 150, 20)];
    task.font = [UIFont systemFontOfSize:14];
    [task setBackgroundColor:[UIColor clearColor]];
    [task setTextAlignment:UITextAlignmentCenter];
    //测试用长度
    NSInteger bb =40;
    
    //完成度进度条背景
    NSString *completeness = [[NSString alloc]initWithFormat:@"今日任务完成：%i%%",bb];
    [task setText:completeness];
    [self.view addSubview:task];
    [task release];
        
    //任务完成度提示图片，包含一个背景图片框和一个进度条
    UIImageView *completenessframe = [[UIImageView alloc]initWithFrame:CGRectMake(135, 71, 148, 15)];
    [completenessframe setImage:[UIImage imageNamed:@"progOut.png"]];
    [self.view addSubview:completenessframe];
    [completenessframe release];
   
    
    if (bb>0 && bb<100) {
    UIImageView *completenessline = [[UIImageView alloc]initWithFrame:CGRectMake(135, 74, 144, 9)];
    [completenessline setImage:[UIImage imageNamed:@"progIn.png"]];
    [self.view addSubview:completenessline];        
    [completenessline release];
    //左边角处理
    UIImageView *compleft = [[UIImageView alloc]initWithFrame:CGRectMake(135, 71, 10, 15)];
    [compleft setImage:[UIImage imageNamed:@"prog_left.png"]];
    [self.view addSubview:compleft];        
    [compleft release];
    UIImageView *black = [[UIImageView alloc]initWithFrame:CGRectMake(135+1.44*bb, 74, 144-1.44*bb, 9)];
    [black setImage:[UIImage imageNamed:@"prog_black"]];
    [self.view addSubview:black]; 
    [black release];
        if (bb >= 100) {
        //右边角边角处理
        UIImageView *compright = [[UIImageView alloc]initWithFrame:CGRectMake(275, 74, 10, 15)];
        [compright setImage:[UIImage imageNamed:@"prog_right.png"]];
        [self.view addSubview:compright];        
        [compright release];
        }
    }
    
    //脂肪消耗提示栏
    UILabel *fatconsume = [[UILabel alloc]initWithFrame:CGRectMake(140, 95, 90, 12)];
    [fatconsume setText:@"您累计消耗脂肪"];
    [fatconsume setBackgroundColor:[UIColor clearColor]];
    [fatconsume setTextAlignment:UITextAlignmentCenter];
    fatconsume.font = [UIFont systemFontOfSize:12];
    [fatconsume setTextColor:[UIColor redColor]];
    [self.view addSubview:fatconsume];
    [fatconsume release];
    
    //脂肪消耗数据
    //测试用数据
    float gg = 13.55;  
    NSMutableString *myfat = [[NSMutableString alloc]initWithFormat:@"%g 千卡",gg];
    
    UIImageView *fatdataFrame = [[UIImageView alloc]initWithFrame:CGRectMake(140, 108, 88, 14 )];
    [fatdataFrame setImage:[UIImage imageNamed:@"kcal.png"]];
    //用Label显示
    UILabel *fatdata = [[UILabel alloc]initWithFrame:CGRectMake(140, 109, 88, 12 )];
    fatdata.font = [UIFont systemFontOfSize:12];
    [fatdata setBackgroundColor:[UIColor clearColor]];
    [fatdata setTextColor:[UIColor whiteColor]];
    [fatdata setTextAlignment:UITextAlignmentCenter];
    [fatdata setText:myfat];
    [self.view addSubview:fatdataFrame];
    [self.view addSubview:fatdata];
    [fatdata release];
    [fatdataFrame release];
    
    //个人信息键
    UIButton *psinfo = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    psinfo = [[UIButton alloc]initWithFrame:CGRectMake(180, 136, 77, 32)];
    [psinfo setTitle:@"个人信息" forState:UIControlStateNormal];
    psinfo.titleLabel.font = [UIFont systemFontOfSize:14];
    [psinfo setBackgroundImage:[UIImage imageNamed:@"btnMyMsg"] forState:UIControlStateNormal];
    [self.view addSubview:psinfo];
    [psinfo release];
    
    //开始键
    UIButton *start = [[UIButton alloc]initWithFrame:CGRectMake(15.5, 225, 86, 86)];
    [start setImage:[UIImage imageNamed:@"start.png"] forState:UIControlStateNormal];
    
    UILabel *startlab = [[UILabel alloc]initWithFrame:CGRectMake(0, 60, 86, 15)];
    startlab.font = [UIFont systemFontOfSize:15];
    [startlab setTextAlignment:UITextAlignmentCenter];
    startlab.text = @"开始";
    [startlab setBackgroundColor:[UIColor clearColor]];
    [startlab setTextColor:[UIColor redColor]];
    
    [self.view addSubview:start];
    [start addSubview:startlab];
    
    [startlab release];
    [start release];
    
    //挑战朋友
    UIButton *PKFriend = [[UIButton alloc]initWithFrame:CGRectMake(117, 225, 86, 86)];
    [PKFriend setImage:[UIImage imageNamed:@"PKFriend.png"] forState:UIControlStateNormal];
    
    UILabel *PKlab = [[UILabel alloc]initWithFrame:CGRectMake(0, 60, 86, 15)];
    PKlab.font = [UIFont systemFontOfSize:15];
    [PKlab setTextAlignment:UITextAlignmentCenter];
    PKlab.text = @"挑战朋友";
    [PKlab setBackgroundColor:[UIColor clearColor]];
    [PKlab setTextColor:[UIColor redColor]];
    
    [self.view addSubview:PKFriend];
    [PKFriend addSubview:PKlab];
    
    //在线竞技
    UIButton *ONLine = [[UIButton alloc]initWithFrame:CGRectMake(218.5, 225, 86, 86)];
    [ONLine setImage:[UIImage imageNamed:@"onLinePlay.png"] forState:UIControlStateNormal];
    
    UILabel *ONLinelab = [[UILabel alloc]initWithFrame:CGRectMake(0, 60, 86, 15)];
    ONLinelab.font = [UIFont systemFontOfSize:15];
    [ONLinelab setTextAlignment:UITextAlignmentCenter];
    ONLinelab.text = @"在线竞技";
    [ONLinelab setBackgroundColor:[UIColor clearColor]];
    [ONLinelab setTextColor:[UIColor redColor]];
    
    [self.view addSubview:ONLine];
    [ONLine addSubview:ONLinelab];
    [ONLinelab release];
    [ONLine release];
    
    //华丽的下划线
    UIImageView *myline =[[UIImageView alloc]initWithFrame:CGRectMake(0, 320, 320, 2)];
    [myline setImage:[UIImage imageNamed:@"line.png"]];
    [self.view addSubview:myline];
    [myline release];
    
    //商店
    UIButton *shop = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    shop = [[UIButton alloc] init];
    [shop setFrame:CGRectMake(20, 335, 86, 35)];
    [shop setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [shop setTitle:@"商店" forState:UIControlStateNormal];
    [shop setBackgroundImage:[UIImage imageNamed:@"btnBelow.png"] forState:UIControlStateNormal] ;
    [shop addTarget:self action:@selector(goShop:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:shop];
    [shop release];
    
    //找朋友
    UIButton *find = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    find = [[UIButton alloc] init];
    [find setFrame:CGRectMake(117, 335, 86, 35)];
    [find setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [find setTitle:@"找朋友" forState:UIControlStateNormal];
    [find setBackgroundImage:[UIImage imageNamed:@"btnBelow.png"] forState:UIControlStateNormal] ;
    [self.view addSubview:find];
    [find release];
    
    //设置
    UIButton *setting = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    setting = [[UIButton alloc] init];
    [setting setFrame:CGRectMake(218.5, 335, 86, 35)];
    [setting setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [setting setTitle:@"设置" forState:UIControlStateNormal];
    [setting setBackgroundImage:[UIImage imageNamed:@"btnBelow.png"] forState:UIControlStateNormal];
    [self.view addSubview:setting];
    [setting release];
    
    //diceng
    UIImageView *buttom = [[UIImageView alloc]initWithFrame:CGRectMake(0, 398, 320, 20)];
    [buttom setImage:[UIImage imageNamed:@"nav_bar.png"]];
    [self.view addSubview:buttom];
    [buttom release];

    //实现循环
    UILabel *scolab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 400, 20)];
    [scolab setText:@"欢迎使用瘦身战争...!   欢迎使用瘦身战争...!"];
    scolab.font = [UIFont fontWithName:@"HelveticaNeue-Italic" size:15];
    [scolab setBackgroundColor:[UIColor clearColor]];
    [scolab setTextColor:[UIColor orangeColor]];

    [scolab sizeToFit];
    CGRect scoframe = scolab.frame;
    scoframe.origin.x = 280;
    scolab.frame = scoframe;
    
    UIScrollView *mysco = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 398, 320, 20)];
    [mysco setScrollEnabled:YES];
    mysco.showsHorizontalScrollIndicator = NO;
    mysco.showsVerticalScrollIndicator = NO;
    mysco.scrollsToTop = NO;
    [mysco addSubview:scolab];
    
    [UIView beginAnimations:@"scrollAnimation" context:nil];
    [UIView setAnimationDuration:10.8f];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationRepeatAutoreverses:NO];
    [UIView setAnimationRepeatCount:9999];
 
    
    scoframe = scolab.frame;
    scoframe.origin.x = -scoframe.size.width;
    scolab.frame = scoframe;
    
    [UIView commitAnimations];
    [self.view addSubview:mysco];
    [scolab release];
    [mysco release];
    
    
}

- (IBAction) goShop:(id)sender
{
    Shopping *shop = [[Shopping alloc] init];
    [self.navigationController pushViewController:shop animated:YES];
    [shop release];
    
}

- (void)viewDidUnload
  {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
  }
    
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void) viewDidAppear:(BOOL)animated
{
    //帮助按钮
    UIButton *helpButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    helpButton.frame = CGRectMake(0, 0, 30, 20);
    helpButton.titleLabel.textColor = [UIColor orangeColor];
    helpButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [helpButton setTitle:@"帮助" forState:UIControlStateNormal];
    [helpButton setBackgroundImage:[UIImage imageNamed:@"nav_button.png"] forState:UIControlStateNormal];
    [helpButton addTarget:self action:@selector(toHelp:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:helpButton] autorelease];
}

- (IBAction) toHelp:(id)sender
{
    
}

- (void)dealloc
{
    [super dealloc];
}

@end
